//   Copyright 2012,2013 Vaughn Vernon
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.

package com.saasovation.agilepm.domain.model.product.sprint;

import com.saasovation.agilepm.domain.model.ValueObject;
import com.saasovation.agilepm.domain.model.product.release.ReleaseId;

/**
 * @值对象：冲刺ID
 */
public class SprintId extends ValueObject {

    /**
     * 身份标识
     */
    private String id;

    /**
     * 由身份标识构造冲刺ID
     * @param anId  身份标识
     */
    public SprintId(String anId) {
        // 调用 父类默认构造器
        super();

        this.setId(anId);
    }

    /**
     * 由发布ID构造冲刺ID
     * @param aReleaseId    发布ID
     */
    public SprintId(ReleaseId aReleaseId) {
        this(aReleaseId.id());
    }

    /**
     * 获取身份识别ID
     * @return  返回身份识别ID
     */
    public String id() {
        return this.id;
    }

    @Override
    public boolean equals(Object anObject) {
        boolean equalObjects = false;

        if (anObject != null && this.getClass() == anObject.getClass()) {
            SprintId typedObject = (SprintId) anObject;
            equalObjects = this.id().equals(typedObject.id());
        }

        return equalObjects;
    }

    @Override
    public int hashCode() {
        int hashCodeValue =
                + (38313 * 43)
                        + this.id().hashCode();

        return hashCodeValue;
    }

    @Override
    public String toString() {
        return "SprintId [id=" + id + "]";
    }

    /**
     * 默认构造器
     */
    protected SprintId() {
        // 调用父类默认构造器
        super();
    }
    /**
     * 设置身份识别ID
     * @param anId  身份识别ID
     */
    private void setId(String anId) {
        this.assertArgumentNotEmpty(anId, "The id must be provided.");
        this.assertArgumentLength(anId, 36, "The id must be 36 characters or less.");

        this.id = anId;
    }
}
